package com.wxy.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wxy.entity.Salemonthdata;
import com.wxy.entity.Saleyeardata;
import com.wxy.mapper.SaleyeardataMapper;
import com.wxy.selectUser.SelectUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;
import java.sql.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wxy
 * @since 2022-01-12
 */
@RestController
@RequestMapping("/saleYearData")
public class SaleyeardataController {

    @Autowired
    private SaleyeardataMapper saleyeardataMapper;
    //按月账单查询
    @GetMapping("/getYearData/{page}")
    public IPage getYearData(
            HttpServletRequest request,
            @PathVariable("page") Integer pageNum
    ){
        //取出page
        QueryWrapper qw =  SelectUser.saleDayDataSelectUser(request.getHeader("userId"));
        qw.orderByDesc("time");
        IPage page = new Page(pageNum,10);
        return saleyeardataMapper.selectPage(page,qw);
    }


    //按年查询
    @GetMapping("/getYearDataByTime/{time}")
    public List getYearDataByTime(
            HttpServletRequest request,
            @PathVariable("time") Integer time
    ){
        //取出page
        QueryWrapper qw =  SelectUser.saleDataSelectUser(request.getHeader("userId"));
        qw.eq("time",time);
        return saleyeardataMapper.selectList(qw);
    }

}

